package com.tangyuan.live.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangyuan.dto.PageDto;
import com.tangyuan.live.service.LiveGiftService;
import com.tangyuan.live.mapper.LiveGiftMapper;
import com.tangyuan.model.live.LiveGift;
import org.springframework.stereotype.Service;



@Service
public class LiveGiftServiceImpl extends ServiceImpl<LiveGiftMapper, LiveGift>
    implements LiveGiftService{

    /**
     * 分页礼物列表
     * @param dto 分页条件
     * @return 礼物
     */
    @Override
    public Page<LiveGift> getPageLiveGift(PageDto dto) {
        LambdaQueryWrapper<LiveGift> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LiveGift::getIsDelete,0);
        Long count = baseMapper.selectCount(wrapper);
        if(count <= 0){
            return new Page<>();
        }
        wrapper.orderByAsc(LiveGift::getGiftPrice);
        Page<LiveGift> page = baseMapper.selectPage(new Page<>(dto.getPageNum(), dto.getPageSize()), wrapper);
        page.setTotal(count);
        return page;
    }

    /**
     * 获取礼物消息
     * @param giveId 礼物ID
     * @return 礼物数据
     */
    @Override
    public LiveGift getGiftById(Long giveId) {
        if(giveId == null || giveId == 0){
            return null;
        }
        return baseMapper.selectById(giveId);
    }
}




